# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//bazel:serving.bzl", "serving_cc_library", "serving_cc_test")

package(default_visibility = ["//visibility:public"])

serving_cc_library(
    name = "feature_adapter",
    deps = [
        ":file_adapter",
        ":http_adapter",
        ":mock_adapter",
        ":streaming_adapter",
    ],
)

serving_cc_library(
    name = "feature_adapter_factory",
    hdrs = ["feature_adapter_factory.h"],
    deps = [
        ":feature_adapter_base",
        "//secretflow_serving/core:singleton",
    ],
)

serving_cc_library(
    name = "feature_adapter_base",
    srcs = ["feature_adapter.cc"],
    hdrs = ["feature_adapter.h"],
    deps = [
        "//secretflow_serving/apis:common_cc_proto",
        "//secretflow_serving/config:feature_config_cc_proto",
        "//secretflow_serving/core:exception",
        "//secretflow_serving/protos:feature_cc_proto",
        "//secretflow_serving/util:arrow_helper",
        "@arrow",
    ],
)

serving_cc_library(
    name = "http_adapter",
    srcs = ["http_adapter.cc"],
    hdrs = ["http_adapter.h"],
    deps = [
        ":feature_adapter_factory",
        "//secretflow_serving/server/trace",
        "//secretflow_serving/spis:batch_feature_service_cc_proto",
        "//secretflow_serving/spis:error_code_cc_proto",
        "//secretflow_serving/util:network",
        "@brpc",
        "@brpc//:json2pb",
        "@yacl//yacl/utils:elapsed_timer",
    ],
    alwayslink = True,
)

serving_cc_library(
    name = "mock_adapter",
    srcs = ["mock_adapter.cc"],
    hdrs = ["mock_adapter.h"],
    deps = [
        ":feature_adapter_factory",
    ],
    alwayslink = True,
)

serving_cc_library(
    name = "file_adapter",
    srcs = ["file_adapter.cc"],
    hdrs = ["file_adapter.h"],
    deps = [
        ":feature_adapter_factory",
        "//secretflow_serving/util:csv_extractor",
    ],
    alwayslink = True,
)

serving_cc_library(
    name = "streaming_adapter",
    srcs = ["streaming_adapter.cc"],
    hdrs = ["streaming_adapter.h"],
    deps = [
        ":feature_adapter_factory",
        "//secretflow_serving/util:csv_util",
        "@gflags",
    ],
    alwayslink = True,
)

serving_cc_test(
    name = "file_adapter_test",
    srcs = ["file_adapter_test.cc"],
    deps = [
        ":file_adapter",
        "@brpc//:butil",
    ],
)

serving_cc_test(
    name = "http_adapter_test",
    srcs = ["http_adapter_test.cc"],
    deps = [
        ":http_adapter",
    ],
)

serving_cc_test(
    name = "mock_adapter_test",
    srcs = ["mock_adapter_test.cc"],
    deps = [
        ":mock_adapter",
    ],
)

serving_cc_test(
    name = "streaming_adapter_test",
    srcs = ["streaming_adapter_test.cc"],
    deps = [
        ":streaming_adapter",
        "@brpc//:butil",
    ],
)
